package cn.doctorpda.meeting.presenter;

import org.json.JSONException;
import org.json.JSONObject;

import cn.doctorpda.meeting.bean.Msg;
import cn.doctorpda.meeting.config.NetConfig;
import cn.doctorpda.meeting.model.GetClientIdModel;
import cn.doctorpda.meeting.model.IGetModel;
import cn.doctorpda.meeting.okhttp.callback.StringCallback;
import cn.doctorpda.meeting.utils.GsonUtil;
import cn.doctorpda.meeting.view.callbackview.IBaseView;
import okhttp3.Call;

/**
 * Created by huangjinlong on 2016/5/13.
 */
public class SplashPresenter {

    private IGetModel getModel;
    private IBaseView baseView;

    public SplashPresenter(IBaseView baseView){
        this.baseView = baseView;
        getModel = new GetClientIdModel();
    }

    public void getClientId(){
        getModel.getNetWorkStringData(NetConfig.GET_CLIENT_ID, new StringCallback() {
            @Override
            public void onError(Call call, Exception e) {

            }

            @Override
            public void onResponse(String response) {
                Msg msg = GsonUtil.fromJson(response, Msg.class);
                JSONObject object = null;
                String clientId = "";
                try {
                    object = new JSONObject(response);
                    clientId = object.getString("client_id");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                baseView.setResult(msg, clientId);
            }
        });
    }
}
